import Vue from 'vue'
import VueRouter from 'vue-router'
import layout from '@/views/Layout/index.vue'

Vue.use(VueRouter)


const routes = [
  { path: '/', redirect: '/findMusic' },
  {
    path: "/findMusic", redirect: '/findMusic/recommend', component: layout, children: [
      { path: "recommend", name: "recommend", component: () => import('@/views/DiscoverMusic/index'), meta: { title: '推荐', tabBarShow: true } },
      { path: "rankinglist", name: "rankinglist", component: () => import('@/views/RankingList/index'), meta: { title: '排行榜', tabBarShow: true } },
      { path: "songsheet", name: "songsheet", component: () => import('@/views/SongSheet/index'), meta: { title: '歌单', tabBarShow: true } },
      { path: "radiostation", name: "radiostation", component: () => import('@/views/RadioStation/index'), meta: { title: '主播电台', tabBarShow: true } },
      { path: "singer", name: "singer", component: () => import('@/views/Singer/index'), meta: { title: '歌手', tabBarShow: true } },
      { path: "newdisc", name: "newdisc", component: () => import('@/views/NewDisc/index'), meta: { title: '新碟上映', tabBarShow: true } },
      { path: "songsheetdetail", name: "songsheetdetail", component: () => import('@/views/SongSheetDetail/index'), meta: { title: '歌单详情', tabBarShow: true } },
      { path: "musicdetail", name: "musicdetail", component: () => import('@/views/MusicDetail/index'), meta: { title: '音乐详情', tabBarShow: true } },
      { path: "radiostationdetail", name: "radiostationdetail", component: () => import('@/views/radioStationDetail/index'), meta: { title: '电台详情', tabBarShow: true } },
      { path: "program", name: "program", component: () => import('@/views/Program/index'), meta: { title: '节目详情', tabBarShow: true } },
      { path: "singerdetail", name: "singerdetail", component: () => import('@/views/SingerDetail/index'), meta: { title: '歌手详情', tabBarShow: true } },
      { path: "album", name: "album", component: () => import('@/views/Album/index'), meta: { title: '专辑', tabBarShow: true } },
    ]
  },
  {
    path: "/mymusic", redirect: '/mymusic/index', component: layout, children: [
      { path: "index", name: "mymusic", component: () => import('@/views/MyMusic/index'), meta: { title: '我的音乐' } },
    ]
  },
  {
    path: "/download", redirect: '/download/index', component: layout, children: [
      { path: "index", name: "download", component: () => import('@/views/Download/index'), meta: { title: '下载客户端' } },
    ]
  },
  {
    path: "/friend", redirect: '/friend/index', component: layout, children: [
      { path: "index", name: "friend", component: () => import('@/views/Friend/index'), meta: { title: '朋友' } },
    ]
  },
  {
    path: "/musician", redirect: '/musician/index', component: layout, children: [
      { path: "index", name: "musician", component: () => import('@/views/Musician/index'), meta: { title: '音乐人' } },
    ]
  },
  {
    path: "/shoppingmall", redirect: '/shoppingmall/index', component: layout, children: [
      { path: "index", name: "shoppingmall", component: () => import('@/views/ShoppingMall/index'), meta: { title: '商城' } },
    ]
  },
  {
    path: "/search", redirect: '/search/index', component: layout, children: [
      { path: "index", name: "search", component: () => import('@/views/Search/index'), meta: { title: '搜索' } },
    ]
  },
  {
    path: "/user", redirect: '/user/home', component: layout, children: [
      {
        path: "index", redirect: '/user/home', component: () => import('@/views/UserLayout/index'),
        children: [
          { path: "uhome", name: "uhome", component: () => import('@/views/PersonalCenter'), meta: { title: '用户主页', tabBarShow: true } },
          { path: "dynamic", name: "dynamic", component: () => import('@/views/Dynamic'), meta: { title: '动态', tabBarShow: true } },
          { path: "follows", name: "Follows", component: () => import('@/views/Follows'), meta: { title: '关注', tabBarShow: true } },
          { path: "fans", name: "Fans", component: () => import('@/views/Fans'), meta: { title: '粉丝', tabBarShow: true } },
        ]
      },
      { path: "news", name: "News", component: () => import('@/views/News'), meta: { title: '消息', tabBarShow: true } },
    ]
  },
  {
    path: "/*",
    redirect: '/findMusic',
  },
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}

export default router
